package com.iwhalecloud.citybrain.flow.platform.manager.application.service.impl;

import com.iwhalecloud.citybrain.flow.platform.manager.application.service.ProcessInstanceStartPostProcessor;
import com.iwhalecloud.citybrain.flow.platform.manager.common.ConstanceVariable;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.repository.FlowReTimeoutSettingRepository;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * 拷贝模型级别配置的超时预警
 *
 * @author lilh
 * @date 2021/4/28 11:13
 */
@Slf4j
@Order(5)
@Component
public class CopyProcessInstanceLevelTimeoutSettingPostProcessor implements ProcessInstanceStartPostProcessor {
    @Autowired
    private FlowReTimeoutSettingRepository flowReTimeoutSettingRepository;

    @Override
    public void process(ExecutionEntity executionEntity) {
        if (log.isDebugEnabled()) {
            log.debug("流程启动后执行拷贝实例级别的超时预警配置");
        }
        flowReTimeoutSettingRepository.copyReTimeoutSetting(executionEntity.getVariable(ConstanceVariable.DEPLOYMENT_ID, String.class), executionEntity.getProcessInstanceId(), null, null);
    }
}
